package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.MrqgdDjList;
import com.htandroid.htandroid.entity.RdrecordAppList;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class abXMLKcapplist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<RdrecordAppList> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("RdrecordAppList=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<RdrecordAppList> rdapp = new ArrayList<RdrecordAppList>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{al_inorder", "{\"al_inorder"));
            try {
                RdrecordAppList info = new RdrecordAppList();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setCvouchtype(string2null(dataJson.getString("cvouchtype")));
                info.setDdate(string2null(dataJson.getString("ddate")));
                info.setCwhcode(string2null(dataJson.getString("cwhcode")));
                info.setCwhname(string2null(dataJson.getString("cwhname")));
                info.setCdepcode(string2null(dataJson.getString("cdepcode")));
                info.setCdepname(string2null(dataJson.getString("cdepname")));
                info.setCirdcode(string2null(dataJson.getString("cirdcode")));
                info.setCirdname(string2null(dataJson.getString("cirdname")));
                info.setCordcode(string2null(dataJson.getString("cordcode")));
                info.setCordname(string2null(dataJson.getString("cordname")));
                info.setCcuscode(string2null(dataJson.getString("ccuscode")));
                info.setCcusname(string2null(dataJson.getString("ccusname")));
                info.setCvencode(string2null(dataJson.getString("cvencode")));
                info.setCvenname(string2null(dataJson.getString("cvenname")));
                info.setCdefine1(string2null(dataJson.getString("cdefine1")));
                info.setCdefine2(string2null(dataJson.getString("cdefine2")));
                info.setCdefine3(string2null(dataJson.getString("cdefine3")));
                info.setCshdefine1(string2null(dataJson.getString("cshdefine1")));
                info.setCshdefine2(string2null(dataJson.getString("cshdefine2")));
                info.setCshdefine3(string2null(dataJson.getString("cshdefine3")));
                info.setCshdefine4(string2null(dataJson.getString("cshdefine4")));
                info.setCmaker(string2null(dataJson.getString("cmaker")));
                info.setChandler(string2null(dataJson.getString("chandler")));
                info.setCmemo(string2null(dataJson.getString("cmemo")));
                info.setCcheckchar(string2null(dataJson.getString("ccheckchar")));
                info.setCnocheckreason(string2null(dataJson.getString("cnocheckreason")));
                info.setLinename(string2null(dataJson.getString("linename")));
                info.setCchar(string2null(dataJson.getString("cchar")));
                info.setAl_inorder(string2null(dataJson.getString("al_inorder")));
                info.setInorder(string2null(dataJson.getString("inorder")));
                info.setCdepchecker(string2null(dataJson.getString("cdepchecker")));
                info.setCmakedate(string2null(dataJson.getString("cmakedate")));
                info.setCchecker(string2null(dataJson.getString("cchecker")));
                info.setCcheckdate(string2null(dataJson.getString("ccheckdate")));
                info.setResign(string2null(dataJson.getString("resign")));
                info.setIsndjz(string2null(dataJson.getString("isndjz")));
                info.setStepall(string2null(dataJson.getString("stepall")));
                rdapp.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return rdapp;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
